from flask import Flask, request, jsonify

app = Flask(__name__)


@app.route("/rpc", methods=["POST"])
def rpc():
    req = request.json
    if req["method"] == "subtract":
        a, b = req["params"]
        return jsonify({"jsonrpc": "2.0", "result": a - b, "id": req["id"]})
    else:
        return jsonify(
            {
                "jsonrpc": "2.0",
                "error": {"code": -32601, "message": "Method not found"},
                "id": req["id"],
            }
        )


if __name__ == "__main__":
    app.run()
